package context.render.camera;

import context.environ.Window;
import math.mat4;
import math.region.Frustum3;
import math.vec2;
import math.vec3;

public class Camera
{
    
    public vec3 mOrig;
    
    public vec3 mAngles;
    
    public vec2 mClipZ;
    
    public double mVertFOV;
    
    public double mAspectRatio;
    
    private Frustum3 mFrustum;
    
    
    public Camera()
    {
        this.mOrig = new vec3();
        this.mAngles = new vec3();
        this.mClipZ = new vec2(0.1, 100.0);
        this.mVertFOV = 80.0;
        this.mAspectRatio = Window.get().aspectRatio();
        this.mFrustum = new Frustum3();
    }
    
    
    public final void updateFrustum()
    {
        this.mFrustum.set(
            this.mOrig, 
            this.mAngles, 
            this.mClipZ, 
            this.mVertFOV, 
            this.mAspectRatio
        );
    }
    
    
    public final mat4 matCameraFromWorld()
    {
        mat4 matRot = mat4.rotateXYZ(this.mAngles);
        mat4 matTransl = mat4.transl(vec3.mul(this.mOrig, -1));
        mat4 matCameraFromWorld = mat4.mul(matRot, matTransl);
        return matCameraFromWorld;
    }
    
    public final mat4 matClipFromCamera()
    {
        mat4 matProj = mat4.perspective(this.mClipZ, this.mAspectRatio, this.mVertFOV);
        return matProj;
    }
    
    
    
}
